package com.zygh.lz.controller;

import com.zygh.lz.dao.PatrolrecordMapper;
import com.zygh.lz.entity.Patrolrecord;
import com.zygh.lz.entity.StationData;
import com.zygh.lz.entity.remould.Patrol;
import com.zygh.lz.service.PatrolrecordService;
import com.zygh.lz.stapprove.ResultUtil;
import com.zygh.lz.stapprove.SysPcLog;
import com.zygh.lz.vo.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 巡查记录
 */
@Api(tags = "PC端巡查记录", description = "PatrolrecordController")
@RestController
public class PatrolrecordController {
    @Resource
    private PatrolrecordService patrolrecordService;
    @Resource
    private PatrolrecordMapper patrolrecordMapper;

    @ApiOperation("查询所有巡查记录")
    @GetMapping("selectAllPatrolrecord")
    public ResultBean selectAllPatrolrecord() {
        return patrolrecordService.selectAllPatrolrecord();
    }


    @ApiOperation("查询所有巡查记录视频")
    @GetMapping("selectVideo")
    public ResultBean selectVideo() {
        return patrolrecordService.selectVideo();
    }


    @ApiOperation("根据开始时间，结束时间、道路名称查询巡查记录")
    @GetMapping("selectDim")
    public ResultBean selectDim(String roadName, String beginTime, String endTime) {
        return patrolrecordService.selectDim(roadName, beginTime, endTime);
    }


    @ApiOperation("根据时间查询个人巡查记录")
    @GetMapping("selectByStaffs")
    public ResultBean selectByStaffs(Integer SysStaffId, String beginTime, String endTime) {
        return patrolrecordService.selectByStaff(SysStaffId, beginTime, endTime);
    }

    @ApiOperation("根据时间查询个人巡查记录app")
    @GetMapping("selectByStaff")
    public ResultBean selectByStaff(Integer SysStaffId, String beginTime, String endTime) {
        return patrolrecordService.selectByStaffapp(SysStaffId, beginTime, endTime);
    }

    @ApiOperation("查询各个大队的巡查记录个数")
    @GetMapping("selectRecordNum")
    public ResultBean selectRecordNum(String startDate, String endDate) {
        return patrolrecordService.selectRecordNum(startDate, endDate);
    }

    @ApiOperation("巡查统计")
    @GetMapping("countPatrolrecord")
    public ResultBean countPatrolrecord(String startTime, String endTime) throws Exception {
        return patrolrecordService.countPatrolrecord(startTime, endTime);
    }


    @ApiOperation("查询最后一条巡查记录")
    @GetMapping("selectBylast")
    public Patrolrecord selectBylast() {
        return patrolrecordMapper.selectBylast();
    }


    @ApiOperation("删除巡查记录")
    @GetMapping("delPatrolrecord")
    @SysPcLog(module = "删除巡查记录",operation = "删除")
    public ResultBean delPatrolrecord(Integer id) {
        return patrolrecordService.delPatrolrecord(id);
    }

    @ApiOperation("批量删除")
    @GetMapping("delectPatrolrecordById")
    @SysPcLog(module = "批量删除巡查记录",operation = "批量删除")
    public ResultBean delectPatrolrecordById(int[] array) {
        return patrolrecordService.delectPatrolrecordById(array);
    }


    @ApiOperation("")
    @GetMapping("theDaySum")
    public List<HashMap> theDaySum(String battalion) {
        return patrolrecordService.theDaySum(battalion);
    }

    @ApiOperation("首页在线实时刷新")
    @GetMapping("typeSum")
    public Map<String, Object> typeSum(String battalion) {
        return patrolrecordService.typeSum(battalion);
    }

    @ApiOperation("首页各大队当前在线人数")
    @GetMapping("onLinePeople")
    public List<Map<String, Object>> onLinePeople(Integer id) {
        return patrolrecordService.onLinePeople(id);
    }


    @ApiOperation("PC首页当前勤务模式各大队部署警力和在线警力统计")
    @GetMapping("countZD")
    public List<Map> countZD(String battalion) throws Exception {
        return patrolrecordService.countZD(battalion);
    }


    @ApiOperation("按时间段统计日间各个岗位应到实到人")
    @GetMapping("typeSumByTime")
    public List<Map> typeSumByTime(String battalion) {
        return patrolrecordService.typeSumByTime(battalion);
    }

    @ApiOperation("方形框选")
    @GetMapping("findNowByGps")
    public List<StationData> findNowByGps(double[] lon, double[] lat, Integer sectionid) {
        return patrolrecordService.findNowByGps(lon, lat, sectionid);
    }

    @ApiOperation("根据大队名称查询在人GPS /热力图")
    @GetMapping("findNowStaffBySection")
    public List<HashMap> findNowStaffBySection(String time, String battalion, Integer type) {
        return patrolrecordService.findNowStaffBySection(time, battalion, type);
    }

    @ApiOperation("根据大队名称统计在线、应到人数")
    @GetMapping("findStaffSum")
    public HashMap findStaffSum(String time, String battalion, Integer type) {
        return patrolrecordService.findStaffSum(time, battalion, type);
    }

    @ApiOperation("判断是否在圆内")
    @GetMapping("findCircleByGps")
    public List<StationData> findCircleByGps(double circleX, double circleY, double r, Integer sectionid) {
        return patrolrecordService.findCircleByGps(circleX, circleY, r, sectionid);
    }


    @ApiOperation("热力图")
    @GetMapping("heatMap")
    public List<HashMap> heatMap(String battalion) {
        return patrolrecordService.heatMap(battalion);
    }

    @ApiOperation("热力图应到部署警力")
    @GetMapping("heatMapYD")
    public List<HashMap> heatMapYD(String battalion) {
        return patrolrecordService.heatMapYD(battalion);
    }

    @ApiOperation("巡查轨迹查询")
    @GetMapping("selectByRoadtype")
    public ResultBean selectByRoadtype(Integer staffid, String beginTime, String endTime, String staffnum, Integer sectionPid,
                                       @RequestParam(defaultValue = "1") int pageNum,
                                       @RequestParam(defaultValue = "10") int pageSize) {
        return patrolrecordService.selectByRoadtype(staffid, beginTime, endTime, staffnum, sectionPid, pageNum, pageSize);


    }

    @ApiOperation("巡查记录导出")
    @GetMapping("exportPatrolRecord")
    public String exportPatrolRecord(HttpServletResponse response, Integer staffid, String beginTime, String endTime,
                                     String staffnum) throws IOException {
        return patrolrecordService.exportPatrolRecord(response, staffid, beginTime, endTime, staffnum);


    }

    @ApiOperation("路长巡查模块》巡查列表")
    @GetMapping("findPatrolrecordInfo")
    public ResultBean findPatrolrecordInfo(Patrol patrol) {
        return ResultUtil.setOK("success", patrolrecordService.findPatrolrecordInfo(patrol));

    }


}
